# 进程
# 进程状态 就绪状态 执行状态 等待状态
import os
import time
from multiprocessing import Process, Queue

# from queue import Queue

# print("Hello Python")
# s = input("请输入：")
# print(s)
# time.sleep(1)


# def sing():
#     print(f"sing 子进程号：{os.getpid()},父进程编号：{os.getppid()}")
#     print("唱歌")


# def dance():
#     print(f"dance 子进程号：{os.getpid()},父进程编号：{os.getppid()}")
#     print("跳舞")


# if __name__ == "__main__":
#     # 创建子进程
#     p1 = Process(target=sing, name="子进程一")
#     p2 = Process(target=dance, name="子进程一")
#     p1.start()
#     p2.start()
#     p1.name = "子进程1"
#     p2.name = "子进程2"
#     print("p1:", p1.name)
#     print("p2:", p2.name)
#     # 子进程编号
#     print("p1 pid", p1.pid)
#     print("p2 pid", p2.pid)
#     print(f"主进程 pid：{os.getpid()} ,主进程父进程pid：{os.getppid()}")


# def eat(name):
#     print(f"{name}在吃饭")


# def sleep(name):
#     print(f"{name}在睡觉")


# if __name__ == "__main__":
#     p1 = Process(target=eat, args=('zhagnsan',))
#     p2 = Process(target=sleep, args=('lisi',))
#     p1.start()
#     p1.join()  # 主进程等待
#     p2.start()
#     print("p1存活状态：", p1.is_alive())
#     print("p2存活状态：", p2.is_alive())
# 进程间通信

# q = Queue(3)
# q.put("消息1")
# q.put("消息2")
# q.put("消息3")
# # 消息是否满
# print(q.full())
# print(q.get())
# print(q.full())
# print(q.get())
# # 消息是否为空
# print(q.empty())
# # 消息长度
# print(q.qsize())
#
# print(q.get())
# print(q.empty())

li = ['zhangsan', 'lisi', 'wangwu', 'zhaoliu']


def wdata(q1):
    for i in range(5):
        print(f"{i}已经被放入")
        q1.put(i)
        time.sleep(0.2)
    print("写入的数据：", li)


def rdata(q2):
    while True:
        if q2.empty():
            break
        else:
            print("取出数据：", q2.get())
    print("读取的数据是：", li)


if __name__ == '__main__':
    q = Queue()
    p1 = Process(target=wdata, args=(q,))
    p2 = Process(target=rdata, args=(q,))
    p1.start()
    p1.join()
    p2.start()

